<template>
  <div>
    <div>
      <FilterTable ref="table" height="500px" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'rows'" :onColumnsChange="columns => (this.columns = columns)" />
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer">返回</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile, arrayObjDeWeight } from '@/utils/index';
import { getVisitInfo } from '@/api/customerRepair/afterSaleVisit/resultEntry';
import {getAllUser } from '@/api/customerRepair/activityVisit/resultEntry';
import { getVisitHistory } from '@/api/customerRepair/afterSaleVisit/resultEntry';
export default {
  name: 'xiaoshouhuifanglishi',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    resData: {
      type: Object,
      default: {}
    }
  },
  data() {
    this.BaseTable = null;
    this.allData = {};
    return {
      fetchApi: getVisitHistory,
      fetchParams: { xhrAbort: true },
      columns: this.createTableColumns()
    };
  },
  computed: {},
  created() {
    this.getResData();
    this.getAllUser();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 140,
          fixed: 'left',
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.exhale(props.row, '0')}>
                  智能外呼
                </el-button>
                <el-button size="mini" type="text" onClick={() => this.exhale(props.row, '00')}>
                  加0外呼
                </el-button>
              </div>
            );
          }
        },
        {
          title: '车主编号',
          dataIndex: 'ownerNo',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '回访单号',
          dataIndex: 'hfdh',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          editable: false
        },
        {
          title: '回访结果',
          dataIndex: 'hfjg',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.hfjg, '1075')}</span>;
          }
        },
        {
          title: '回访状态原因',
          dataIndex: 'hfztyy',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.createDictText(props.row.hfztyy, '8084')}</span>;
          }
        },
        {
          title: '回访人',
          dataIndex: 'hfr',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editable: false,
          editItems: []
        },
        {
          title: '回访时间',
          dataIndex: 'hfrq',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          width:  150
        },

        {
          title: '满意度得分',
          dataIndex: 'myddf',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'bz',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售顾问',
          dataIndex: 'xsgw',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          editType: 'select',
          editable: false
        },
        {
          title: '客户名称',
          dataIndex: 'khmc',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户电话',
          dataIndex: 'khdh',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人',
          dataIndex: 'lxr',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人手机',
          // dataIndex: 'lxrsj',
          dataIndex: 'lxryddh',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'cximc',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'cxingmc',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户地址',
          dataIndex: 'khdz',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成交日期',
          dataIndex: 'cjrq',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },

        {
          title: '车牌号',
          dataIndex: 'pzh',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    mounted() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    async getResData(val) {
      let parm = {
        visitType: this.resData.visitType,
        ownerNo: this.resData.ownerNo,
        pzh: this.resData.pzh,
        khmc:this.resData.khmc,
        returnVisitInfoId: this.resData.returnVisitInfoId
      };
      this.fetchParams = Object.assign({}, parm, { xhrAbort: false });
    },
    async getAllUser() {
      const res = await getAllUser();
      let data = arrayObjDeWeight(res.data, 'userId'); // 人员去重(解决前端报错)
      this.columns.find(item => item.dataIndex === 'hfr').editItems = data.map(x => ({
        value: x.userId,
        text:  x.employeeName
      }));;
    },
    // 关闭页面
    closeDrawer() {
      this.$emit('close', false);
    }
  }
};
</script>

<style lang="less" scoped></style>
